/**
 * --------------------------------------------------------------------------
 * Hi.js (v1.0.0): Tab.js
 * require jquery
 * --------------------------------------------------------------------------
 */

;(function($, window, document, undefined) {
    "use strict";

	//定义Message的构造函数
    var Tab = function(elem) {
        this.elem = $(elem);
        this.init();
        this.bind();
    }

    Tab.VERSION = '1.0.0';

    Tab.prototype.Constructor = Tab;
    Tab.prototype.init = function() {
    };
    Tab.prototype.bind = function() {
        this.elem.find('.nav-tabs>.nav-item>.nav-link').bind('click', $.proxy(this['_tabChange'], this));
    };
    Tab.prototype._tabChange = function(e) {
        $(e.target).closest('.nav-tabs').find('.nav-item').removeClass('active');
        $(e.target).parent().addClass('active');
        this.elem.find('.tab-content>.tab-pane').hide();
        $('#' + $(e.target).attr('aria-controls')).fadeIn('fast');
    };

    //在插件中使用Tab扩展
    $.fn.tab = function() {
        return this.each(function() {
            new Tab(this);
        });
    }

    $('.tab').tab();
})(jQuery, window, document);